package com.shujia.utils;

import java.io.BufferedReader;
import java.io.FileReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Map;
import java.util.Properties;

/*
    与mysql数据库操作的工具类
 */
public class MySQLTool {
    private MySQLTool(){}

    //读取配置文件信息，返回数据库连接信息
    public static Connection getMySqlConnection(){

        Connection connection = null;
        try {
            //读取配置文件
            //创建配置文件对象
            Properties properties = new Properties();
            //加载本地的一个配置文件
            properties.load(new BufferedReader(new FileReader("redis/src/main/resources/mysqlInfo.properties")));

            String url = (String) properties.get("url");
            String userName = (String) properties.get("userName");
            String password = (String) properties.get("password");


            Class.forName("com.mysql.jdbc.Driver");
            //获取与数据库的连接对象
            connection = DriverManager.getConnection(url,userName,password);

        }catch (Exception e){
            e.printStackTrace();
        }

        return connection;
    }
}
